/** 格式化星期 */
export const formatWeek = (week: number) => {
  switch (week) {
    case 0:
      return '星期日'
    case 1:
      return '星期一'
    case 2:
      return '星期二'
    case 3:
      return '星期三'
    case 4:
      return '星期四'
    case 5:
      return '星期五'
    case 6:
      return '星期六'
  }
}

/** 单位选择器数据 */
export interface SelectorItem {
  label: string
  value: number
}

/** 根据单位生成选择器遍历数组 */
export const generateSelectorByUnit = (unit: string) => {
  const arr = [] as SelectorItem[]

  switch (unit) {
    case '碗':
      for (let i = 1; i <= 5; i++) {
        arr.push({
          label: `${i}${unit}`,
          value: i,
        })
      }
      break
    case 'g':
      for (let i = 50; i <= 400; i += 50) {
        arr.push({
          label: `${i}${unit}`,
          value: i,
        })
      }
    case '分钟':
      for (let i = 10; i <= 60; i += 10) {
        arr.push({
          label: `${i}${unit}`,
          value: i,
        })
      }
      break
    case '个':
      for (let i = 10; i <= 60; i += 10) {
        arr.push({
          label: `${i}${unit}`,
          value: i,
        })
      }
  }

  return arr
}

/** 计划条件选择器 */
export interface PlanConditionSelector {
  text: string
  value: string
}

/** 根据用户的选择生成数据集 */
export const listByUserSelect = (value: string) => {
  const arr: PlanConditionSelector[] = []
  const weightArr: PlanConditionSelector[][] = []
  switch (value) {
    case 'age':
      for (let i = 14; i <= 51; i++) {
        if (i == 14) {
          arr.push({
            text: '15岁以下',
            value: '15岁以下',
          })
        } else if (i == 51) {
          arr.push({
            text: '50岁以上',
            value: '50岁以上',
          })
        } else {
          arr.push({
            text: `${i}岁`,
            value: `${i}岁`,
          })
        }
      }
      return arr
    case 'height':
      for (let i = 149; i <= 191; i++) {
        if (i == 149) {
          arr.push({
            text: '150cm以下',
            value: '150cm以下',
          })
        } else if (i == 191) {
          arr.push({
            text: '190cm以上',
            value: '190cm以上',
          })
        } else {
          arr.push({
            text: `${i}cm`,
            value: `${i}cm`,
          })
        }
      }
      return arr
    case 'weight':
      weightArr[0] = []
      weightArr[1] = []
      for (let i = 40; i <= 120; i++) {
        weightArr[0].push({
          text: `${i}`,
          value: `${i}`,
        })
      }

      for (let i = 0; i < 60; i++) {
        weightArr[1].push({
          text: `${i < 10 ? '0' + i : i}`,
          value: `${i < 10 ? '0' + i : i}`,
        })
      }
      return weightArr
    case 'targetWeight':
      weightArr[0] = []
      weightArr[1] = []
      for (let i = 40; i <= 120; i++) {
        weightArr[0].push({
          text: `${i}`,
          value: `${i}`,
        })
      }

      for (let i = 0; i < 60; i++) {
        weightArr[1].push({
          text: `${i < 10 ? '0' + i : i}`,
          value: `${i < 10 ? '0' + i : i}`,
        })
      }
      return weightArr
    case 'eatScene':
      return [
        { text: '食堂', value: '食堂' },
        { text: '家', value: '家' },
        { text: '外卖', value: '外卖' },
      ]
    case 'sportAbility':
      return [
        { text: '从未锻炼', value: '从未锻炼' },
        { text: '偶尔锻炼', value: '偶尔锻炼' },
        { text: '经常锻炼', value: '经常锻炼' },
      ]
    case 'food_weight':
      for (let i = 100; i <= 1000; i += 100) {
        arr.push({
          text: `${i} 克`,
          value: `${i} 克`,
        })
      }
      return arr
    case '个':
      for (let i = 50; i <= 1000; i += 50) {
        arr.push({
          text: `${i} 个`,
          value: `${i} 个`,
        })
      }
      return arr
    case '分钟':
      for (let i = 10; i <= 60; i += 10) {
        arr.push({
          text: `${i} 分钟`,
          value: `${i} 分钟`,
        })
      }
      return arr
  }
}

/** 根据两个过滤器生成结果 */
export const getResultOnTwoFilter = (filter: string, value: number | string) => {
  if (filter == 'sport_ability') {
    switch (value) {
      case 1.375:
        return '从未锻炼'
      case 1.55:
        return '偶尔锻炼'
      case 1.725:
        return '经常锻炼'
      case '从未锻炼':
        return 1.375
      case '偶尔锻炼':
        return 1.55
      case '经常锻炼':
        return 1.725
    }
  } else if (filter == 'eat_scene') {
    switch (value) {
      case 0:
        return '食堂'
      case 1:
        return '家'
      case 2:
        return '外卖'
      case '食堂':
        return 0
      case '家':
        return 1
      case '外卖':
        return 2
    }
  }
}
